﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;

namespace ScFramework.Core
{

    public class InputManager: SystemModule{

        private static VirtualInput activeInput;
        public List<KeyCode> UseableKeys = new List<KeyCode>();

        // Use this for initialization
        public override void Initialize(Main m)
        {
            base.Initialize(m);
            activeInput = new StandaloneInput();
            for (var x = KeyCode.Keypad0; x <= KeyCode.Keypad9; x++)
            {
                UseableKeys.Add(x);
            }
            for (var x = KeyCode.UpArrow; x <= KeyCode.LeftArrow; x++)
            {
                UseableKeys.Add(x);
            }
            for (var x = KeyCode.A; x <= KeyCode.Z; x++)
            {
                UseableKeys.Add(x);
            }
            UseableKeys.Add(KeyCode.Space);
        }
	    public bool GetButton(string name)
        {
            return activeInput.GetButton(name);
        }

        public bool GetButtonDown(string name)
        {
            return activeInput.GetButtonDown(name);
        }

        public bool GetButtonUp(string name)
        {
            return activeInput.GetButtonUp(name);
        }

        public float GetAxis(string name,bool raw=false)
        {
            return activeInput.GetAxis(name, raw);
        }


        public bool GetKeyDown(KeyCode key)
        {
            return activeInput.GetKeyDown(key);
        }

        public bool GetKey(KeyCode key)
        {
            return activeInput.GetKey(key);
        }

        public bool GetKeyUp(KeyCode key)
        {
            return activeInput.GetKeyUp(key);
        }

        
        public Vector3 MousePosition
        {
            get {
#if TEST_UI
                var cache =
                GameObject.FindObjectOfType<UIEditCache>();
                if (cache != null && cache.UseMousePosition == false)
                {
                    return cache.TmpMousePosition;
                }
#endif
                
                
                return activeInput.MousePosition(); }
        }
        public Vector3 MouseWorldPosition
        {
            get
            {
                return Camera.main.ScreenToWorldPoint(MousePosition);
            }

        }

    }

}